import { LoggerService } from '@nestjs/common';
import dayjs from 'dayjs';
import { createLogger, Logger } from 'winston';

export class MyLogger implements LoggerService {

  private logger: Logger;

  constructor(options: any) {
    // super();
    this.logger = createLogger(options);
  }

  log(message: string, context: string) {
    const time = this.getNowTime();
    this.logger.log('info', message, { context, time });
  }

  error(message: string, context: string) {
    const time = this.getNowTime();
    this.logger.log('info', message, { context, time });
  }

  warn(message: string, context: string) {
    const time = this.getNowTime();
    this.logger.log('info', message, { context, time });
  }

  getNowTime() {
    return dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss');
  }
}
